@extends('layouts.app') @section('content')

<div class="container">
    <div class="row">
        <div class="col-md-10 col-md-offset-1">
            <div>
                <img class="category-home-title" src="/lv5/public/img/category.png" alt="">
            </div>
            <div class="category-home">
                @foreach ($categories as $category)
                <div style="width: 280px;margin-left: 18px; margin-top:50px; margin-bottom: 20px; border:1px solid #E6E6E6; border-radius: 10px; background-color:#F8F8F8;">
                    <div style="position: relative; width:100%; height:55px;">
                        <div style="position: absolute; top: -35px; left:50%; transform: translateX(-50%);">
                            <img src="/lv5/public/img/category/{{ $category->category_img }}" alt="" style="width: 70px; height:70px; border-radius: 10px;">
                        </div>
                    </div>
                    <div style="text-align: center;">
                        <p>
                            <a href="{{ url('category').'?name='.$category->name }}">{{ $category->name }}</a>
                        </p>
                        <p style="padding-bottom: 18px; line-height: 26px; margin:0 auto; width: 85%; word-wrap:break-word;">{{ substr($category->intro, 0, 90).'...' }}</p>
                        <?php 

                                $user_array = explode(',', $category->follower); 

                            ?> @if (Auth::guest())
                        <a href="{{ url('/login') }}" class="btn btn-primary">+ 关注</a>
                        @elseif ($category->founder == Auth::user()->id && Request::getRequestUri() == '/lv5/public/index.php/category/user'.'?user='.Auth::user()->id)
                        <a href="{{ url('category/'.$category->id.'/edit') }}" class="btn btn-success">修改</a>
                        <form style="display:inline-block;" action="{{ url('category/'.$category->id) }}" method="POST">
                            {{ method_field('DELETE') }} {{ csrf_field() }}
                            <button class="btn btn-danger" type="submit">删除</button>
                        </form>
                        @elseif ($category->founder == Auth::user()->id)
                        <button class="btn btn-primary" disabled>已关注</button>
                        @else
                        <?php $b = 1; ?> @foreach ($user_array as $user_id ) @if ($user_id == Auth::user()->no_id )
                        <a href="{{ url('category/unfollow?category='.$category->id) }}" class="btn btn-primary">已关注</a>
                        <?php $b = 0; ?> @endif @endforeach @if($b == 1)
                        <a href="{{ url('category/follow?category='.$category->id) }}" class="btn btn-primary">+ 关注</a>
                        @endif @endif

                        <hr style="width:80%;">
                        <p style="margin-bottom: 10px;">
                            <span>{{ $category->page_num }}篇文章</span>&nbsp;&nbsp;&nbsp;&nbsp;
                            <span></span>
                        </p>
                    </div>
                </div>
                @endforeach
            </div>
        </div>
    </div>
</div>

    @endsection